/*
 * FileName: 编辑页面
 * Created Date: 2022-10-12 18:03:35
 * Author: 文初阳
 * -----
 * Last Modified: 2022-10-12 18:07:42
 * Modified By: 文初阳
 */

import { Button, Checkbox, Form, Input, Layout, PageHeader } from 'antd';
import { Content } from 'antd/lib/layout/layout';
import React, { useContext } from 'react';
import { editResumeApi } from '../../apis/resume';
import { RESUME_BASE_INFO } from '../../constants/resume/resume';
import { formatResumeData } from '../../services/editRequest';
import { EditContext } from '../../states/edit/edit';
import { ResumeContext } from '../../states/resume';
import BaseInfo from './baseInfo/BaseInfo';
import styles from './Edit.module.scss';
import EducationExperiences from './educationExperiences/EducationExperiences';
import PersonalSkills from './personalSkills/PersonalSkills';
import ProjectExperiences from './projectExperiences/ProjectExperiences';
import WorkExperiences from './workExperiences/WorkExperiences';

/**
 * 1. 姓名+一句话简介
 * 2. 求职岗位
 * 3. 关于你自己（可以有多段）
 * 4. 不同平台链接（多个）
 * 5. 联系方式（可以有多个）
 * 6. 技能信息（大标题+标题&内容，内容可以加高亮）
 * 7. 工作经历（时间、公司、职位 + 描述信息）
 *      描述信息可分段，每一段有标题+简要描述+细节
 *      细节里边分段，标题+描述（内容可高亮）
 * 8. 项目信息（标题+简要描述+细节描述+图片）
 * 9. 教育信息（时间、学校、专业 + 描述信息）
 */
const Edit: React.FC = () => {
    const onFinish = (values: any) => {
        console.log('Success:', values);
        const data = formatResumeData(values);
        console.log('========================');
        console.log(data);
        editResumeApi(data).then((res: any) => {
            console.log(res);
        });
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };
    const { pageName, setPageName } = useContext(ResumeContext);
    const subTitle = pageName === 'add' ? '简历新增' : '简历编辑';
    const handleBack = () => setPageName('list');
    return (
        <Layout>
            <PageHeader className="site-page-header" onBack={handleBack} title="返回" subTitle={subTitle}></PageHeader>
            <Content className={styles.wrapper}>
                <EditContext.Provider value={RESUME_BASE_INFO}>
                    <Form
                        name="resume"
                        layout="inline"
                        labelCol={{ span: 4 }}
                        wrapperCol={{ span: 20 }}
                        initialValues={{ remember: true }}
                        onFinish={onFinish}
                        onFinishFailed={onFinishFailed}
                        autoComplete="off"
                    >
                        <div className={styles.nameWrapper}>
                            <Form.Item label="简历名称" name="resumeName" rules={[{ required: true }]}>
                                <Input placeholder="比如：简历1号" />
                            </Form.Item>
                        </div>
                        <BaseInfo />
                        <PersonalSkills />
                        <WorkExperiences />
                        <ProjectExperiences />
                        <EducationExperiences />
                        <div className={styles.btnWrapper}>
                            <Button type="primary" size="large" htmlType="submit">
                                提交
                            </Button>
                        </div>
                    </Form>
                </EditContext.Provider>
            </Content>
        </Layout>
    );
};

export default Edit;
